<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel app\models\search\SysSourceSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Sys Sources');
$this->params['breadcrumbs'][] = $this->title;
?>
  <div class="layui-fluid">
    <div class="layui-card p30">		
		<div class="border-b pb15 f22">商品管理</div>
		<div class="layui-row layui-col-space20 mt15">
			<div class="layui-col-sm2">
				<a class="layui-btn layui-btn-normal" href="/admingoods/publish/index?goodstype=1">发布资源</a>
				<a class="layui-btn layui-btn-normal" href="/admingoods/publish/index?goodstype=7">发布设备</a>
			</div>
            <div class="layui-col-xs12">
				<form class="layui-form " action="/admingoods/default/index">	
					<div class="layui-form-item">
					  <div class="layui-inline">
						<label class="layui-form-label">商品类型</label>
						<div class="layui-input-inline">
						  <select name="first_cate" lay-verify="required">
							  <option value=""></option>
							  <option value="1" <?= $condition['first_cate']==1 ?'selected':'' ?>>广告资源</option>
							  <option value="7" <?= $condition['first_cate']==7 ?'selected':'' ?>>广告设备</option>
							</select>
						</div>
					  </div>
					  <div class="layui-inline">
							<label class="layui-form-label">商品名称</label>
							<div class="layui-input-inline">
							  <input type="text" name="name" value="<?=$condition['name']?>" placeholder="请输入商品名称!" class="layui-input">
							</div>
					  </div>
					  <div class="layui-inline">
						<label class="layui-form-label">卖家</label>
						<div class="layui-input-inline">
						  <input type="text" name="seller" value="<?=$condition['seller']?>" placeholder="请输入卖家名称!" class="layui-input">
						</div>
					  </div>
					  <div class="layui-inline">
						<label class="layui-form-label">卖家ID</label>
						<div class="layui-input-inline">
						  <input type="text" name="seller_id" value="<?=$condition['seller_id']?>" placeholder="请输入卖家ID!" class="layui-input">
						</div>
					  </div>
					  <div class="layui-inline">
					   <button class="layui-btn layui-btn-normal layui-icon layui-icon-search">  搜索</button>
					  </div>
					</div>
					
					
				</form>
			</div>
		</div>
		
		<div class="layui-card-body p0 mt15">			
			<table class="layui-table">					
				<thead>
					<tr>
					  <th>ID</th>
					  <th>商品名称</th>
					  <th>商品价格</th>
					  <th>卖家</th>
					  <th>添加时间</th>
					  <th>商品类型</th>
					  <th>商品状态</th>
					  <th>操作</th>
					</tr> 
				</thead>
			  <tbody>
				<?php foreach($data['goodsdata'] as $goods){?>  
				
				<tr>
				  <td><?= $goods['id'] ?></td>
				  <td><?= $goods['name'] ?></td>
				  <td><?= $goods['price'] ?></td>
				  <td><?= $goods['seller'] ?>（<?= $goods['seller_id'] ?>）</td>
				  <td><?= $goods['addtime'] ?></td>
				  <td><?= $category_arr[$goods['first_cate']] ?><!--<?= $category_arr[$goods['second_cate']] ?><?= $category_arr[$goods['third_cate']] ?> --></td>
				  
				  <td>
					  <span class="layui-badge layui-bg-green <?php if($goods['status']==2){ //已下架的商品才能编辑?> layui-bg-gray<?php }?>">
					  	<?= $status_arr[$goods['status']] ?>
					  </span>
				  </td>
				  <td>
					<?php if($goods['status']==2){ //已下架的商品才能编辑?>
						<a class="layui-btn layui-btn-xs onsale" data-id="<?= $goods['id']?>">上架</a>
						<a class="layui-btn layui-btn-normal layui-btn-xs" href="/admingoods/publish/update?goods_id=<?= $goods['id']?>"><i class="layui-icon layui-icon-edit"></i>编辑</a>			
					<?php }else if($goods['status']==1){ ?>
						<a class="layui-btn layui-btn-xs layui-btn-warm offsale" data-id="<?= $goods['id']?>">下架</a>
					<?php }?>
						
						<a class="layui-btn layui-btn-danger layui-btn-xs delete" data-id="<?= $goods['id']?>" ><i class="layui-icon layui-icon-delete"></i>删除</a>
                   </td>
				</tr>
				<?php }?>
				</tbody>
			</table>
			
			<div class="p-tradelist-pager text-c"><?= $page?></div>		
		</div>
    </div>
  </div>
<script>
$(".onsale").on('click',function(){
    var goods_id = $(this).attr('data-id');
    layer.confirm('您确定要删除该条数据', {btn: ['删除', '取消' ]}, function(index, layero){
        $params = JSON.stringify({'status':1,'goods_id':goods_id});
        onsale_back = ajaxSynchroRequest("/admingoods/default/set-status",$params);
        if(onsale_back.success==1){
            layer.msg(onsale_back.msg);
            layer.close(index);
            window.location.reload();
        }
    });
});
$(".offsale").on('click',function(){
	var goods_id = $(this).attr('data-id');
	layer.confirm('您确定要下架该商品吗？', {btn: ['确定', '取消' ]}, function(index, layero){
		$params = JSON.stringify({'status':2,'goods_id':goods_id});
		offsale_back = ajaxSynchroRequest("/admingoods/default/set-status",$params);
		if(offsale_back.success==1){
			layer.msg(offsale_back.msg);
			layer.close(index);
			window.location.reload();
		}
	});
});
$(".delete").on('click',function(){
    var goods_id = $(this).attr('data-id');
    layer.confirm('您确定要删除该条数据', {btn: ['删除', '取消' ]}, function(index, layero){
        $params = JSON.stringify({'status':4,'goods_id':goods_id});
        delete_back = ajaxSynchroRequest("/admingoods/default/set-status",$params);
        if(delete_back.success==1){
            layer.msg(delete_back.msg);
            layer.close(index);
            window.location.reload();
        }
    });
});

</script>

